home *** CD-ROM | disk | FTP | other *** search
/ The PC-SIG Library 10 / The PC-Sig Library - Shareware for the IBM PC and Compatibles (PC-SIG)(Tenth Edition Disks 1-2804)(1991).iso / PC_SIGCD / 04 / 2 / DISK0425.ZIP / DETERM.PAS < prev    next >
Pascal/Delphi Source File  |  1985-04-03  |  1KB  |  71 lines

  1. program determ;        { -> 55 }
  2. { pascal program to calculate the determinant of a 3-by-3matrix }
  3.  
  4. type    ary2    = array[1..3,1..3] of real;
  5.  
  6. var    a    : ary2;
  7.     n    : integer;
  8.     yesno    : char;
  9.     d    : real;
  10.  
  11. external procedure cls;
  12.  
  13. procedure get_data(var a: ary2;
  14.            var n: integer);
  15.  
  16. { get values for n and arrays x,y }
  17.  
  18. var    i,j    : integer;
  19.  
  20. begin
  21.   n:=3;
  22.   writeln;
  23.   for i:=1 to n do
  24.     begin
  25.     for j:=1 to n do
  26.       begin
  27.         write(j:3,':');
  28.         readln(a[i,j])
  29.     end    { j-loop }
  30.   end;        { i-loop }
  31.   writeln;
  32.   for i:=1 to n do
  33.     begin
  34.     for j:=1 to n do
  35.       write(a[i,j]:7:4,' ');
  36.     writeln
  37.     end;
  38.     writeln
  39.     end;    { procedure get_data }
  40.  
  41.  
  42.  
  43.  
  44. function deter(a: ary2): real;
  45.     { calculate the determinant of a 3-by-3matrix }
  46.  
  47. var
  48.     sum    : real;
  49.  
  50. begin
  51.   sum:=a[1,1]*(a[2,2]*a[3,3]-a[3,2]*a[2,3])
  52.     -a[1,2]*(a[2,1]*a[3,3]-a[3,1]*a[2,3])
  53.     +a[1,3]*(a[2,1]*a[3,2]-a[3,1]*a[2,2]);
  54.   deter:=sum
  55. end;
  56.  
  57.  
  58.  
  59. begin        { MAIN program }
  60.   cls;
  61.   repeat
  62.     get_data(a,n);
  63.     d:=deter(a);
  64.     writeln('The determinant is',d);
  65.     writeln;
  66.     write('More?');
  67.     readln(yesno);
  68.     cls
  69.   until (yesno<>'Y')and(yesno<>'y')
  70. end.
  71.